package o;

import android.net.Uri;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import com.google.android.exoplayer2.util.PriorityTaskManager;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.EOFException;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

public final class amb {
    public static final amf ˎ = ame.ˋ;

    public static String ˎ(Uri uri) {
        return uri.toString();
    }

    public static String ॱ(DataSpec dataSpec) {
        return dataSpec.ʻ != null ? dataSpec.ʻ : ˎ(dataSpec.ˎ);
    }

    public static void ॱ(DataSpec dataSpec, Cache cache, d dVar) {
        String ॱ = ॱ(dataSpec);
        long j = dataSpec.ˊ;
        long ˎ = dataSpec.ᐝ != -1 ? dataSpec.ᐝ : cache.ˎ(ॱ);
        dVar.attrValueRefName = ˎ;
        dVar.ˎ = 0;
        dVar.ˋ = 0;
        long j2 = ˎ;
        ˎ = j;
        while (j2 != 0) {
            j = cache.ˊ(ॱ, ˎ, j2 != -1 ? j2 : Long.MAX_VALUE);
            if (j > 0) {
                dVar.ˎ += j;
            } else {
                j = -j;
                if (j == Long.MAX_VALUE) {
                    return;
                }
            }
            long j3 = ˎ + j;
            if (j2 == -1) {
                ˎ = 0;
            } else {
                ˎ = j;
            }
            j2 -= ˎ;
            ˎ = j3;
        }
    }

    public static void ॱ(DataSpec dataSpec, Cache cache, alj o_alj, @Nullable d dVar, @Nullable AtomicBoolean atomicBoolean) throws IOException, InterruptedException {
        ˏ(dataSpec, cache, new CacheDataSource(cache, o_alj), new byte[WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT], null, 0, dVar, atomicBoolean, false);
    }

    public static void ˏ(DataSpec dataSpec, Cache cache, CacheDataSource cacheDataSource, byte[] bArr, PriorityTaskManager priorityTaskManager, int i, @Nullable d dVar, @Nullable AtomicBoolean atomicBoolean, boolean z) throws IOException, InterruptedException {
        d dVar2;
        amm.ॱ(cacheDataSource);
        amm.ॱ(bArr);
        if (dVar != null) {
            ॱ(dataSpec, cache, dVar);
            dVar2 = dVar;
        } else {
            dVar2 = new d();
        }
        String ॱ = ॱ(dataSpec);
        long ˎ = dataSpec.ᐝ != -1 ? dataSpec.ᐝ : cache.ˎ(ॱ);
        long j = dataSpec.ˊ;
        while (ˎ != 0) {
            ˋ(atomicBoolean);
            long ˊ = cache.ˊ(ॱ, j, ˎ != -1 ? ˎ : Long.MAX_VALUE);
            if (ˊ <= 0) {
                long j2 = -ˊ;
                if (ˎ(dataSpec, j, j2, cacheDataSource, bArr, priorityTaskManager, i, dVar2, atomicBoolean) >= j2) {
                    ˊ = j2;
                } else if (z && ˎ != -1) {
                    throw new EOFException();
                } else {
                    return;
                }
            }
            long j3 = j + ˊ;
            if (ˎ == -1) {
                j = 0;
            } else {
                j = ˊ;
            }
            ˎ -= j;
            j = j3;
        }
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static long ˎ(com.google.android.exoplayer2.upstream.DataSpec r15, long r16, long r18, o.alj r20, byte[] r21, com.google.android.exoplayer2.util.PriorityTaskManager r22, int r23, o.amb.d r24, java.util.concurrent.atomic.AtomicBoolean r25) throws java.io.IOException, java.lang.InterruptedException {
        /*
        r14 = r15;
    L_0x0001:
        if (r22 == 0) goto L_0x0006;
    L_0x0003:
        r22.ˊ(r23);
    L_0x0006:
        ˋ(r25);	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r2 = new com.google.android.exoplayer2.upstream.DataSpec;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r3 = r14.ˎ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r4 = r14.ॱ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r5 = r14.ˋ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r6 = r14.ॱॱ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r6 = r6 + r16;
        r8 = r14.ˊ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r8 = r6 - r8;
        r10 = -1;
        r12 = r14.ʻ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r6 = r14.ʽ;	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r13 = r6 | 2;
        r6 = r16;
        r2.<init>(r3, r4, r5, r6, r8, r10, r12, r13);	 Catch:{ PriorityTooLowException -> 0x009b, all -> 0x0096 }
        r0 = r20;
        r4 = r0.ˋ(r2);	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r0 = r24;
        r6 = r0.ˏ;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r8 = -1;
        r3 = (r6 > r8 ? 1 : (r6 == r8 ? 0 : -1));
        if (r3 != 0) goto L_0x0043;
    L_0x0036:
        r6 = -1;
        r3 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1));
        if (r3 == 0) goto L_0x0043;
    L_0x003c:
        r6 = r2.ˊ;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r4 = r4 + r6;
        r0 = r24;
        r0.ˏ = r4;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
    L_0x0043:
        r4 = 0;
    L_0x0045:
        r3 = (r4 > r18 ? 1 : (r4 == r18 ? 0 : -1));
        if (r3 == 0) goto L_0x007a;
    L_0x0049:
        ˋ(r25);	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r6 = 0;
        r8 = -1;
        r3 = (r18 > r8 ? 1 : (r18 == r8 ? 0 : -1));
        if (r3 == 0) goto L_0x007e;
    L_0x0053:
        r0 = r21;
        r3 = r0.length;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r8 = (long) r3;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r10 = r18 - r4;
        r8 = java.lang.Math.min(r8, r10);	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r3 = (int) r8;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
    L_0x005e:
        r0 = r20;
        r1 = r21;
        r3 = r0.ˋ(r1, r6, r3);	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r6 = -1;
        if (r3 != r6) goto L_0x0082;
    L_0x0069:
        r0 = r24;
        r6 = r0.ˏ;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r8 = -1;
        r3 = (r6 > r8 ? 1 : (r6 == r8 ? 0 : -1));
        if (r3 != 0) goto L_0x007a;
    L_0x0073:
        r6 = r2.ˊ;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r6 = r6 + r4;
        r0 = r24;
        r0.ˏ = r6;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
    L_0x007a:
        o.anr.ˋ(r20);
        return r4;
    L_0x007e:
        r0 = r21;
        r3 = r0.length;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        goto L_0x005e;
    L_0x0082:
        r6 = (long) r3;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r4 = r4 + r6;
        r0 = r24;
        r6 = r0.ˋ;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r8 = (long) r3;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        r6 = r6 + r8;
        r0 = r24;
        r0.ˋ = r6;	 Catch:{ PriorityTooLowException -> 0x008f, all -> 0x0096 }
        goto L_0x0045;
    L_0x008f:
        r3 = move-exception;
    L_0x0090:
        o.anr.ˋ(r20);
        r14 = r2;
        goto L_0x0001;
    L_0x0096:
        r2 = move-exception;
        o.anr.ˋ(r20);
        throw r2;
    L_0x009b:
        r2 = move-exception;
        r2 = r14;
        goto L_0x0090;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.amb.ˎ(com.google.android.exoplayer2.upstream.DataSpec, long, long, o.alj, byte[], com.google.android.exoplayer2.util.PriorityTaskManager, int, o.amb$d, java.util.concurrent.atomic.AtomicBoolean):long");
    }

    private static void ˋ(AtomicBoolean atomicBoolean) throws InterruptedException {
        if (Thread.interrupted() || (atomicBoolean != null && atomicBoolean.get())) {
            throw new InterruptedException();
        }
    }
}
